<template>
  <div>
    <h1>文件上传-formdata</h1>
    <input type="file" ref="file">
    <button @click="upload">上传</button>
  </div>
</template>
<script>
import axios from "axios";
export default {
  methods: {
    upload() {
      // 获取文件域里的文件信息
      const file = this.$refs.file.files[0]
      console.log(file)
      // 创建一个formdata对象
      const formdata = new FormData();
      // formdata 对象直接log看不到添加的数据
      formdata.append("hehe",file)
      console.log(formdata.get("hehe"))
      const url = "http://localhost:3000/file/upload"
      axios.post(url,formdata).then((res) => {
        console.log(res)
      })

    }
  }
}
</script>